﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Net.Fan.SmallPig.Common;
using Net.Fan.SmallPig.BusinessRules;

public partial class Admin_SystemSetting : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            PagePermission.CheckIsAdmin(this);

            TextBoxShortTitle.Text = Config.Instance.ShortTitle;
            TextBoxWebTitle.Text = Config.Instance.WebTitle;
            bool HaveProductKey = false;
            object hp = Application["ProductKeyPass"];
            if (hp != null)
            {
                HaveProductKey = (bool)hp;
            }
            if (HaveProductKey)
            {
                PanelProductKey.Visible = false;
            }
            else
            {
                PanelProductKey.Visible = true;
                LabelFeatureCode.Text = SN.GetMachineId();
            }



        }
    }
    protected void ButtonSave_Click(object sender, EventArgs e)
    {
        Config.Instance.WebTitle = TextBoxWebTitle.Text.Trim();
        Config.Instance.ShortTitle = TextBoxShortTitle.Text.Trim();
        Config.Instance.SaveConfig(BaseConfig.ConfigXmlFilePath);


    }
    protected void ButtonValidateProductKey_Click(object sender, EventArgs e)
    {
        string pk = TextBoxProductKey.Text.Trim();
        bool pass = SystemSettingBiz.CheckPK(pk);
        if (pass)
        {
            SystemSettingBiz.SavePK(pk);
            Application["ProductKeyPass"] = true;
            Response.Redirect(Request.RawUrl);
        }
        else
        {
            LabelMessage.Text = "序列号错误！";
        }

    }
}
